package com.esa.servlet.course;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.esa.dbi.impl.CourseDBImpl;
import com.esa.javabean.Course;


public class AddCourseServlet extends HttpServlet {
	public void doGet(HttpServletRequest request,HttpServletResponse response)
	throws ServletException,IOException{
		response.setContentType("text/html");
		PrintWriter out=response.getWriter();
		this.doPost(request, response);
		out.flush();
		out.close();
	}
	
	public void doPost(HttpServletRequest request,HttpServletResponse response)
	throws ServletException,IOException{
		response.setContentType("text/html");
		PrintWriter out=response.getWriter();
		
		String cno=request.getParameter("cno");
		String cname=request.getParameter("cname");
		String credit=request.getParameter("credit");
		String cteacher=request.getParameter("cteacher");
		String cplace=request.getParameter("cplace");
		String cshare=request.getParameter("chare");
		
		Course course=new Course();
		course.setCno(cno);
		course.setCname(cname);
		course.setCredit(credit);
		course.setCteacher(cteacher);
		course.setCplace(cplace);
		course.setCshare(cshare);
		
		CourseDBImpl cdbi=new CourseDBImpl();
		cdbi.addCourse(course);
		//System.out.println("AddUserServlet line 48....");
		//request.getRequestDispatcher("addUser.jsp").forward(request,response);
		response.sendRedirect("ShowAllCoursesServlet");
		out.flush();
		out.close();
		
	}

}
